<template>
    <view class="life-container">
        <!-- 固定头部区域 -->
        <view class="fixed-header" v-if="author_id">
            <view class="info-box">
                <image class="avatar" :src="authorInfo.headimg" mode="aspectFill"></image>
                <view class="info-box-text">
                    <text class="name">{{ authorInfo.nickname }}</text>
                    <text class="fans">{{ authorInfo.fans }}关注</text>
                </view>
                <button class="follow-btn" :style="{ backgroundColor: t('color1') }" @tap="toggleFollow">
                    <text class="follow-text">{{ isFollow ? '已关注' : '关注' }}</text>
                </button>
            </view>
            <view class="info-box2">
                <text class="introduction">简介：{{ authorInfo.introduction }}</text>
            </view>
        </view>

        <!-- 可滚动的内容区域 -->
        <view class="content-container">
            <!-- <scroll-view class="scrollable-content" scroll-y="true"> -->
            <view class="content-grid" v-if="contentList.length > 0">
                <view class="content-card" v-for="(item, index) in contentList" :key="index" @tap="toDetail(item)">
                    <image class="card-image" :src="item.image" mode="aspectFill"></image>
                    <view class="card-info">
                        <text class="card-title">{{ item.name }}</text>
                        <view class="user-info">
                            <image class="user-avatar" :src="item.author_headimg" mode="aspectFill"></image>
                            <text class="user-name">{{ item.author_nickname }}</text>
                            <text class="view-count">{{ item.pageviews }}</text>
                        </view>
                    </view>
                </view>
            </view>
            <view class="content-tip" v-if="nodata">
                暂无数据
            </view>
            <nomore text="没有更多内容了" v-if="nomore"></nomore>
            <!-- </scroll-view> -->
        </view>
    </view>
</template>

<script>
var app = getApp();
export default {
    data() {
        return {
            nomore: false,
            nodata: false,
            isFollow: false,
            author_id: '',
            pagenum: 1,
            limit: 10,
            id: '',
            contentList: [],
            authorInfo: {}
        }
    },
    computed: {

    },

    onShow() {
        this.getdata();
    },

    onLoad: function (opt) {
        this.id = opt.id;
        this.getdata()
    },
    onPullDownRefresh: function () {
        this.getdata();
    },

    onReachBottom: function () {
        if (!this.nodata && !this.nomore) {
            this.pagenum = this.pagenum + 1;
            this.getdata();
        }
    },
    methods: {

        getdata() {
            app.showLoading('加载中');
            var that = this;
            that.nodata = false;
            that.nomore = false;
            app.get('VideoCenter/authorVideoList', { author_id: that.id, limit: that.limit, page: that.pagenum }, function (res) {
                if (res && res.status == 200) {
                    app.showLoading(false);
                    that.authorInfo = res.data.author;
                    that.author_id = res.data.author.id;
                    that.isFollow = res.data.author.is_involved;
                    if (that.pagenum == 1) {
                        that.contentList = res.data.list;
                        if (res.data.list.length == 0) {
                            that.nodata = true;
                        }
                    } else {
                        if (res.data.list.length == 0) {
                            that.nomore = true;
                        } else {
                            var datalist = that.contentList;
                            var newdata = datalist.concat(res.data.list);
                            that.contentList = newdata;
                        }
                    }
                } else {
                    that.nodata = true;
                    app.showLoading(false);
                    app.error(res.msg);
                }
                that.loaded();
            });

        },

        toggleFollow() {
            let that = this;
            that.isFollow = !that.isFollow;
            app.post('VideoCenter/authorInvolved', { video_center_content_id: that.listid, author_id: that.author_id, type: !that.isFollow ? 2 : 1 }, function (res) {
                if (res && res.status == 200) {
                    if (that.isFollow) {
                        // app.success('收藏成功');
                    }
                } else {
                    if (res.msg == "已关注此视频") {
                    } else {
                        app.error(res.msg);
                        that.isFollow = !that.isFollow;
                    }
                }
            });
        },

        toDetail(item) {
            uni.navigateTo({
                url: `/pagesZone/video/video_detail?id=${item.id}`
            })
        }
    }
}
</script>

<style lang="scss">
.life-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: #f5f5f5;
    padding: 20rpx;

    .search-container {
        width: 100%;
        height: 94rpx;
        // padding: 16rpx 23rpx 14rpx 23rpx;
        position: relative;
        overflow: hidden;
        // border-bottom: 1px solid #f5f5f5;

        .search-box {
            display: flex;
            align-items: center;
            height: 70rpx;
            border-radius: 16rpx;
            border: 0;
            background-color: #f7f7f7;
            flex: 1;
        }

        .search-box .img {
            width: 46rpx;
            height: 44rpx;
            margin-right: 10rpx;
            margin-left: 30rpx
        }

        .search-box .search-text {
            font-size: 24rpx;
            color: #939393;
            width: 100%;
        }

    }



    .fixed-header {
        width: 100%;
        background: #fff;
        border-radius: 15rpx;
        overflow: hidden;
        box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
        margin-bottom: 20rpx;

        .info-box {
            display: flex;
            align-items: center;
            height: 150rpx;
            // margin-left: 20rpx;

            .avatar {
                max-width: 110rpx;
                max-height: 110rpx;
                border-radius: 50%;
                margin: 0 20rpx;
            }

            .info-box-text {
                display: flex;
                flex-direction: column;
                justify-content: center;

                .name {
                    font-size: 34rpx;
                    color: #666;
                    flex: 1;
                    margin: 10rpx;
                }

                .fans {
                    font-size: 29rpx;
                    color: #666;
                    flex: 1;
                    margin: 10rpx;
                }

            }

            .follow-btn {
                background: #ba1f25;
                color: #fff;
                padding: 0rpx 12rpx;
                border-radius: 10rpx;
                font-size: 30rpx;
                height: 50rpx;
                line-height: 50rpx;
                margin-right: 30rpx;
                min-width: 120rpx;
            }
        }

        .info-box2 {
            margin: 20rpx;
            margin-bottom: 40rpx;

            .introduction {
                font-size: 27rpx;
                color: gray;
                margin: 0 0rpx;
            }
        }
    }

    // .scrollable-content {
    .content-container {

        width: 100%;
        // margin-top: 106rpx;
        font-size: 26rpx;
        height: 0;

        .content-tip {
            text-align: center;
            color: #999;
            font-size: 28rpx;
            padding: 20rpx;
        }

        .content-grid {
            display: flex;
            flex-wrap: wrap;
            margin: 0 -10rpx;

            .content-card {
                width: calc(50% - 20rpx);
                margin: 10rpx;
                background: #fff;
                border-radius: 15rpx;
                overflow: hidden;
                box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);

                .card-image {
                    width: 100%;
                    height: 200rpx;
                }

                .card-info {
                    padding: 20rpx;


                    .card-title {
                        font-size: 28rpx;
                        color: #333;
                        line-height: 1.4;
                        margin-bottom: 10rpx;
                        white-space: nowrap;
                        overflow: hidden;
                        text-overflow: ellipsis;
                        display: block;
                    }

                    .user-info {
                        display: flex;
                        align-items: center;

                        .user-avatar {
                            width: 40rpx;
                            height: 40rpx;
                            border-radius: 50%;
                            margin-right: 10rpx;
                        }

                        .user-name {
                            font-size: 24rpx;
                            color: #666;
                            flex: 1;
                        }

                        .view-count {
                            font-size: 24rpx;
                            color: #999;

                            &::before {
                                content: '';
                                display: inline-block;
                                width: 24rpx;
                                height: 24rpx;
                                background: url('@/pagesSocial/static/img/view.png') no-repeat;
                                background-size: contain;
                                vertical-align: middle;
                                margin-right: 6rpx;
                            }
                        }
                    }
                }
            }
        }

        .content-grid2 {
            display: flex;
            flex-wrap: wrap;
            margin: 0 -10rpx;


            .content-card2 {
                width: 100%;
                margin: 10rpx;
                background: #fff;
                border-radius: 15rpx;
                overflow: hidden;
                box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);

                // .card-image {
                //     width: 100%;
                //     height: 200rpx;
                // }

                .info-box {
                    display: flex;
                    align-items: center;
                    height: 150rpx;
                    margin-left: 20rpx;

                    .avatar {
                        width: 110rpx;
                        height: 110rpx;
                        border-radius: 50%;
                        margin-right: 10rpx;
                    }

                    .info-box-text {
                        display: flex;
                        flex-direction: column;
                        justify-content: center;

                        .name {
                            font-size: 34rpx;
                            color: #666;
                            flex: 1;
                            margin: 10rpx;
                        }

                        .fans {
                            font-size: 29rpx;
                            color: #666;
                            flex: 1;
                            margin: 10rpx;
                        }

                    }
                }
            }
        }
    }

}
</style>
